/**
 * Config对象，系统通用配置函数
 * 可配置的参数包括：
 * 	server: 请求数据的服务器地址
 *  mainpage: 首页
 */
/*global define window Base64 :true*/
define(["jquery"], function($) {
    function Config() {
        this.server = window.location.origin + "/web/";
        this.project = "demo";

        // true表示访问node_server, false表示由系统框架转发
        this.debug = true;
        this.debugRequestPath = window.location.origin;
        this.requestPath = this.server + "CommonRequestHandler.do?method=handleRequest";

        this.basepage = this.project + "/main.html";
        this.homepage = {
            "url": this.project + "/homepage.html",
            "moduleName": "page_home"
        };
    }

    Config.prototype.getRequestUrl = function(tempUrl) {
        var url = this.requestPath;
        if (this.debug) {
            url = this.debugRequestPath + tempUrl.local;
        }
        return url;
    };

    Config.prototype.getHomepage = function() {
        return this.getUrl(this.homepage);
    };

    Config.prototype.getUrl = function(path, params) {
        var paramStr = "";
        if ($.isNotBlank(params)) {
            paramStr = Base64.encode(JSON.stringify(params));
        }
        return this.server + this.basepage + "?_p=" + Base64.encode(path) + "&_a=" + paramStr;
    };

    Config.prototype.getLocation = function(page) {
        return this.server + page;
    };

    Config.prototype.getLocalRequestUrl = function(className, method) {
        return this.server + className + ".do?method=" + method;
    };

    return Config;
});
